package br.edu.univas.si.lab3.bankmanager.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JPanel;

import br.edu.univas.si.lab3.bankmanager.listeners.BotoesListener;
import br.edu.univas.si.lab3.bankmanager.model.DAOException;


public class PanelOKButton extends JPanel{
	private static final long serialVersionUID = 1L;

	private JButton okButton;
	
	private ArrayList<BotoesListener> listenersBotoes = new ArrayList<BotoesListener>();
	
	public PanelOKButton() {
		initialize();
	}

	private void initialize() {
		add(getOkButton());
	}

	private JButton getOkButton() {
		if(okButton == null) {
			okButton = new JButton();
			okButton.setText("OK");
			okButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					for (BotoesListener listener : listenersBotoes) {
						try {
							listener.okPerformed();
						} catch (DAOException e) {
							e.printStackTrace();
						}
					}
				}
			});
		}
		return okButton;
	}

	public void addBotoesListeners(BotoesListener listener) {
		listenersBotoes.add(listener);
		
	}
}
